import hyRequest from "../..";
import { getCurrentToken } from "../login";
const token = getCurrentToken();

/**
 *
 * @param query
 * @获取病人列表
 */
export function getPatientsUserInfo(query: {
  pageNum?: number;
  pageSize?: number;
}) {
  return hyRequest
    .get({
      url: "/user/list",
      headers: {
        Authorization: `Bearer ${token}`,
      },
      params: query, // 注意这里虽然变量叫query，但在axios/request中要使用params
    })
    .then((res) => {
      return res;
    });
}

/**
 * @获取部门列表
 */
export function getDepartmentList() {
  return hyRequest
    .get({
      url: "system/dept/list",
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })
    .then((res) => {
      // console.log(res);
      return res.data;
    });
}

/**
 * @body
 * @获取医生列表
 */
export function getDoctorsList(body: {
  deptId: "";
  doctorId: "";
  nurseId: "";
}) {
  return hyRequest
    .post({
      url: "/user/doctors/",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json", //body传参要配置这个
      },
      data: body, //使用data传递请求体,
    })
    .then((res) => {
      return res;
    });
}
/**
 * @body
 * @获取护士列表
 */
export function getNurseLists(body: { deptId: ""; doctorId: ""; nurseId: "" }) {
  return hyRequest
    .post({
      url: "/user/nurses/",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
      data: body,
    })
    .then((res) => {
      return res;
    });
}
/**
 * @获取病种列表
 */
export function getIllnessList() {
  return hyRequest
    .get({
      url: "/illness/listAll",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
    })
    .then((res) => {
      return res;
    });
}

/**
 * @获取检查项目列表
 * @血常规...
 */
export function getExaminationList() {
  return hyRequest
    .get({
      url: "/examination/listAll",
      headers: {
        Authorization: `Bearer ${token}`,
        "Content-Type": "application/json",
      },
    })
    .then((res) => {
      return res;
    });
}

/**
 * @病人对应的检查和任务
 */
export function getTaskExaminationByUserId(query: { userId: number }) {
  return hyRequest
    .get({
      url: "/submit/getTaskExaminationByUserId",
      headers: {
        Authorization: `Bearer ${token}`,
      },
      params: query,
    })
    .then((res) => {
      return res;
    });
}

/**
 * @更新检查修改
 */
export function updateExamination(body: {
  userId: number;
  examinationList: Array<{
    userRelevancyId?: number;
    id: number | null;
    timeOn: string | null;
    state: string | null;
  }>;
  examinationListUpdate: any[];
}) {
  return hyRequest.post({
    url: "/submit/updateExamination",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}
/**
 * @任务列表
 */
export function getTaskList() {
  return hyRequest
    .get({
      url: "/task/listAll",
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })
    .then((res) => {
      return res;
    });
}

/**
 * @修改提交的任务
 */

export function updateTask(body: {
  examinationList: any[];
  examinationListUpdate: any[];
  taskList: Array<{
    userRelevancyId?: number;
    id: number | null;
    timeOn: string | null;
    deadline: string | null;
    state: string;
  }>;
  userId: number;
  taskListUpdate: any[];
}) {
  return hyRequest
    .post({
      url: "/submit/updateTask",
      headers: {
        Authorization: `Bearer ${token}`,
      },
      data: body,
    })
    .then((res) => {
      return res;
    });
}

/**
 * @病人详细信息
 */

export function getPatientDetailInfo(userId: number) {
  return hyRequest
    .get({
      url: `/user/${userId}`,
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })
    .then((res) => {
      return res;
    });
}

/**
 * @获取病人完成比例
 */
export function getPatientRate(userId: number) {
  return hyRequest
    .get({
      url: `/user/getRate/${userId}`,
      headers: {
        Authorization: `Bearer ${token}`,
      },
    })
    .then((res) => {
      return res;
    });
}

/**
 * @导出任务列表
 */
export function exportTasks(params: any) {
  return hyRequest.post({
    url: "/task/export",
    params,
    headers: {
      Authorization: `Bearer ${token}`,
    },
    responseType: "blob", // 重要：接收二进制流
  });
}

/**
 * @导出检查列表
 */
export function exportExaminations(params: any) {
  return hyRequest.post({
    url: "/examination/export",
    params,
    headers: {
      Authorization: `Bearer ${token}`,
    },
    responseType: "blob", // 重要：接收二进制流
  });
}

/**
 * @修改检查任务
 */
export function updateTaskExamination(body: {
  examinationList: {
    id: number;
    state: string | null;
    timeOn: string | null;
  }[];
  examinationListUpdate: any[];
  taskList: {
    deadline: string | null;
    id: number;
    state: string | null;
    timeOn: string | null;
  }[];
  taskListUpdate: any[];
  userId: number;
}) {
  return hyRequest.post({
    url: "/submit/updateTaskExamination",
    headers: {
      Authorization: `Bearer ${token}`,
    },
    data: body,
  });
}
/**
 *@修改病人信息
 */
export function modifyPatientInfor(params: {
  avatar?: string;
  createBy: string | null;
  createTime: string | null;
  deptId?: number;
  dischargeDate?: string;
  doctorId?: number;
  email?: string;
  familyHistory?: string;
  hospitalId?: number;
  hospitalizationDate?: string;
  id: number;
  illnessId?: number;
  image?: string;
  medicalRecord?: string;
  name?: string;
  nickName?: string;
  nurseId?: number;
  operation?: string;
  operationDate?: string;
  pastMedicalHistory?: string;
  programmeTitle: string | null;
  phonenumber?: string;
  programmeId?: number;
  sex?: string;
  remark: null;
  updateBy: null;
  state?: string;
  userId?: number;
  username?: string;
  updateTime?: string | null;
}) {
  return hyRequest.post({
    url: "/user/updateUserInfo",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${token}`,
    },
    data: params,
  });
}

/**
 * @删除用户信息
 */
export function deletePatientInfo(userId: number) {
  return hyRequest.delete({
    url: `/user/${userId}`,
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${token}`,
    },
  });
}
